package com.xja.service.impl;/**
 * @className: BlogServiceImpl
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/17
 **/

import com.xja.mapper.*;
import com.xja.pojo.*;
import com.xja.pojo.Article;
import com.xja.pojo.BlogUsers;
import com.xja.pojo.ContentType;
import com.xja.pojo.CourseInfo;
import com.xja.pojo.CoursePerson;
import com.xja.service.BlogService;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName : BlogServiceImpl  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/17  10:50
 */
@Service
public class BlogServiceImpl implements BlogService {
    private Logger logger= LoggerFactory.getLogger(BlogService.class);
    @Autowired
    ArticleMapper articleMapper;
    @Autowired
    ContentTypeMapper contentTypeMapper;
    @Autowired
    BlogMapper blogMapper;
    @Autowired
    CoursePersonMapper coursePersonMapper;
    @Autowired
    CourseInfoMapper courseInfoMapper;


    @Transactional(readOnly = true)
    @Override
    public List<Article> getHotestArticle() {
        logger.info("最火文章业务层");
        List<Article> hotestArticle = articleMapper.getHotestArticle();
        return hotestArticle;
    }
    @Transactional(readOnly = true)
    @Override
    public List<ContentType> selectConType() {
        return contentTypeMapper.selectConType();
    }

    @Transactional(readOnly = true)
    @Override
    public List<BlogUsers> getHotestUser() {
        return articleMapper.getHotestUser();
    }



    @Transactional(readOnly = true)
    @Override
    public List<CourseInfo> getCourseInfoList(CourseInfo courseInfo) {
       return blogMapper.getCourseInfoList(courseInfo);
    }

    @Transactional(readOnly = true)
    @Override
    public CourseInfo getCourseInfoById(Integer cid) {
        return blogMapper.getCourseInfoById(cid);
    }

    @Transactional(readOnly = true)
    @Override
    public Article getarticleById(Integer aid) {
        return articleMapper.getarticleById(aid);
    }

    @Transactional(readOnly = true)
    @Override
    public List<ArticleComment> getCommentById(Integer aid, Integer count) {
        return articleMapper.getComment(aid,count);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Article> getLikeArticles(Integer typeid,Integer aid) {
        return articleMapper.getLikeArticles(typeid,aid);
    }
    @Transactional(readOnly = true)
    @Override
    public List<ArticleComment> getdateArticlesList(Integer aid, Integer count) {
        return articleMapper.getdateArticlesList(aid,count);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void addreadtime(Integer aid) {
        articleMapper.addreadtime(aid);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Boolean insertCoursePerson(CoursePerson coursePerson) {
        int a = coursePersonMapper.insert(coursePerson);
        int b = courseInfoMapper.coursePersonnumber(coursePerson.getCid());
        if (a>0&&b>0){
            return true;
        }
        return false;
    }

    @Transactional(readOnly = true)
    @Override
    public List<ArticleComment> getAllComment() {
        return blogMapper.getAllComment();
    }

    @Transactional(readOnly = true)
    @Override
    public List<ArticleCollInfo> getcollList(Integer uid) {
        return blogMapper.getcollList(uid);
    }

    @Override
    public void addexrep(Integer uid, String format,String content) {
        blogMapper.addexrep(uid,format,content);
    }

    @Transactional(readOnly = true)
    @Override
    public List<Article> getArticleList(Article article) {
      return articleMapper.getArticleList(article);
    }

    @Transactional(readOnly = true)
    @Override
    public int getPersonCountByCid(Integer cid,Integer uid) {
      return   coursePersonMapper.getPersonCountByCid(cid,uid);
    }


}
